package com.binguo.model.mapper;

import com.binguo.model.model.ShopQucanguiSmsConfig;
import com.binguo.model.model.SideBoardCellDetail;
import com.binguo.model.model.SideBoardCellDetailExample;

import java.util.Date;
import java.util.List;

import com.binguo.model.model.SideBoardCells;
import com.binguo.model.wxapi.vo.OpenCellByCardNoVO;
import com.binguo.model.wxapi.vo.SMSOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface SideBoardCellDetailMapper {
    int countByExample(SideBoardCellDetailExample example);

    int deleteByExample(SideBoardCellDetailExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(SideBoardCellDetail record);

    int insertSelective(SideBoardCellDetail record);

    List<SideBoardCellDetail> selectByExample(SideBoardCellDetailExample example);

    SideBoardCellDetail selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") SideBoardCellDetail record, @Param("example") SideBoardCellDetailExample example);

    int updateByExample(@Param("record") SideBoardCellDetail record, @Param("example") SideBoardCellDetailExample example);

    int updateByPrimaryKeySelective(SideBoardCellDetail record);

    int updateByPrimaryKey(SideBoardCellDetail record);

    SideBoardCellDetail selectByOrderIdAndCell(@Param("orderId") String orderId);

    List<OpenCellByCardNoVO> selectByCustomerId(@Param("customerId") Integer customerId);

    @Select("select distinct meal_code from side_board_cell_detail where order_id = #{orderId} and branch_id = #{branchId} and shop_id = #{shopId}")
    String selectMealCodeByOrderNoAndShopIdAndBranchId(@Param("orderId")String orderNo,@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);

    @Select("select distinct order_id from side_board_cell_detail  where order_status in(0 , 1) and meal_code = #{mealCode} and shop_id = #{shopId} and branch_id = #{branchId}")
    String selectOrderIdByShopIdAndBranchIdAndMealCode(@Param("mealCode")String mealCode,@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);

    @Select("select distinct meal_code from side_board_cell_detail where branch_id = #{branchId} and meal_code != '' and side_board_cell_detail.order_status in(0,1);")
    List<String> selectAllMealCodeInBranch(@Param("branchId") Integer branchId);

    @Select("select * from side_board_cell_detail where order_id = #{orderId} and order_status = 2")
    List<SideBoardCellDetail> selectByOrderId(@Param("orderId")String orderId);

    @Select("select id as id ,start_time as startTime,end_time as endTime,cell as cell,shop_id as shopId , branch_id as branchId ,side_board_id as sideBoardId from side_board_cell_detail where order_id = #{orderId} and order_status = 1 and meal_code = #{mealCode}")
    List<SideBoardCellDetail> selectSaveOrderDetail(@Param("orderId")String orderId,@Param("mealCode")String mealCode);

    Integer updateSideBoardCellDetailsByList(@Param("details")List<SideBoardCellDetail> sideBoardCellDetail);

    @Select("select  id as id,order_status as orderStatus,meal_code as mealCode from side_board_cell_detail where order_id = #{orderId}")
    List<SideBoardCellDetail> selectOrderStatus(@Param("orderId")String orderId);

    @Select("select  distinct meal_code from side_board_cell_detail where order_id = #{orderId}")
    String selectMealCode(@Param("orderId")String orderId);

    @Select("select * from side_board_cell_detail where meal_code = #{mealCode} and order_status = 0;")
    List<SideBoardCellDetail> isTrueMealCode(@Param("mealCode")String mealCode);

    @Select("select side_board_cell_detail.meal_code from side_board_cell_detail INNER JOIN binguo_order on binguo_order.orderNo = side_board_cell_detail.order_id where binguo_order.customerId = #{customerId} and side_board_cell_detail.order_status = 1 and  side_board_cell_detail.branch_id = #{branchId} and side_board_cell_detail.shop_id = #{shopId}")
    List<String> getCustomerMealCodes(@Param("customerId")Integer customerId,@Param("branchId") Integer branchId,@Param("shopId") Integer shopId);

    @Select("select distinct order_status from side_board_cell_detail where order_id = #{orderId}")
    Integer selectStatus(@Param("orderId")String orderId);

    List<SMSOrderVO> selectSMSOrder(@Param("detail")ShopQucanguiSmsConfig shopQucanguiSmsConfig);

    List<SMSOrderVO> selectSMSOrderBySetting(@Param("detail")ShopQucanguiSmsConfig shopQucanguiSmsConfig);

    List<SideBoardCellDetail> selectSideBoardCellDetail(@Param("sideBoardId")Integer sideBoardId,@Param("orderSN")String orderSN);

    @Select("SELECT side_board_cell_detail.end_time FROM `side_board_cell_detail` INNER JOIN binguo_order on binguo_order.orderNo = side_board_cell_detail.order_id where binguo_order.transactionId = #{orderSN} limit 1")
    Date selectSideBoardCellDetailByOrderSN(@Param("orderSN")String orderSN);


    List<String> selectOrderIdByShopIdAndBranchIdAndMealCodes(@Param("mealCodes")String[] mealCode,@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);


    List<SideBoardCellDetail> selectSaveOrderDetails(@Param("orderIds")List<String> orderIds,@Param("mealCodes")String[] mealCodes);

    List<SideBoardCellDetail> selectSideBoardCellDetailByCellNo(@Param("sideBoardId")Integer sideBoardId,@Param("cellNos")String[] cellNos);

    @Select("select * from side_board_cell_detail \n" +
            "where side_board_cell_detail.side_board_id = #{sideBoardId}\n" +
            "and side_board_cell_detail.cell = #{cell} and side_board_cell_detail.branch_id = #{branchId} and side_board_cell_detail.shop_id = #{shopId}\n" +
            "and order_status != 2\n")
    SideBoardCellDetail selectSideBoardCellDetailCellByHendDa(@Param("sideBoardId") Integer sideBoardId,@Param("cell")String cellNo,@Param("branchId")Integer branchId,@Param("shopId")Integer shopId);

    @Select("select id as id,order_id as orderId,start_time as startTime,end_time as endTime,cell as cell,shop_id as shopId,branch_id as branchId,order_status as orderStatus,meal_code as mealCode,side_board_id as sideBoardId,create_time as createTime,phone as phone from side_board_cell_detail where  side_board_cell_detail.meal_code = #{mealCode} and side_board_cell_detail.branch_id = #{branchId} and side_board_cell_detail.shop_id = #{shopId} and order_status != #{status} limit 1")
    SideBoardCellDetail selectSideBoardCellDetailCell(@Param("mealCode")String mealCode,@Param("branchId")Integer branchId,@Param("shopId")Integer shopId,@Param("status")int status);
}